#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3f;
const int M = 5e5 + 10;
const int Mod = 998244353;

vector<int> s1(M), s2(M), s3(M);
vector<int> pre(M);
void Init()
{
    pre[0] = 1;
    for (int i = 1; i < M; i++) pre[i] = (pre[i - 1] * i) % Mod;
    s1[1] = 1, s2[1] = 1, s3[1] = 1;
    for (int i = 2; i < M; i++)
    {
        s1[i] = ((i * s1[i - 1]) % Mod + pre[i - 1]) % Mod;
        s2[i] = (((i * s2[i - 1]) % Mod + (2 * s1[i - 1]) % Mod) % Mod + pre[i - 1]) % Mod;
        s3[i] = ((((i * s3[i - 1]) % Mod + (3 * s2[i - 1]) % Mod) % Mod + (3 * s1[i - 1]) % Mod) % Mod + pre[i - 1]) % Mod;
    }
}

void solve()
{
    int n;
    cin >> n;
    cout << s3[n] << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int _ = 1;
    Init();
    cin >> _;
    while (_--)
    {
        solve();
    }
    return 0;
}